package com.mexico.inloancash.activity;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.mexico.inloancash.R;
import com.mexico.inloancash.bean.India_User_Message_ListInfoBean;
import com.mexico.inloancash.utils.India_Customized_ClickableSpan;

import org.greenrobot.eventbus.EventBus;

/**
 * 权限申请告知页面
 */
public class IndiaPermissionCheckActivity extends BaseActivity {

    private TextView textView;
    private CheckBox checkBox;
    private Button button;
    private TextView mTextView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.india_permission_layout);
        textView = findViewById(R.id.tv_xieyi);
        checkBox = findViewById(R.id.select_all);
        button = findViewById(R.id.btn_per_confirm);
        mTextView = findViewById(R.id.tv_xieyi);
        getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
        india_Set_Immersive();
        //textView.setText(Html.fromHtml("<p>Al continuar acepta nuestra <font color=\"#46C0F6\"> Términos de servicio </font>&<font color=\"#46C0F6\"> Pólitica de privacidad </font>y recibir comunicación de Préstamos rápidos por SMS y correo electrónico </p>"));
        textView.setText("Por favor, acepte nuestro");
        String str = " Condiciones de servicio ";
        SpannableString spStr = new SpannableString(str);
        ClickableSpan clickSpan = new India_Customized_ClickableSpan(str,this);
        spStr.setSpan(clickSpan, 0, str.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.append(spStr);
        textView.append("&");
        String str2 = " Política de privacidad ";
        SpannableString spStr2 = new SpannableString(str2);
        ClickableSpan clickSpan2 = new India_Customized_ClickableSpan(str2,this);
        spStr2.setSpan(clickSpan2, 0, str2.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.append(spStr2);

        textView.append("y recibir comunicaciones por SMS y correo electrónico para préstamos rápidos ");
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        //去掉点击文字之后的背景
        textView.setHighlightColor(Color.parseColor("#00ffffff"));

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!checkBox.isChecked()) {
                    Toast.makeText(IndiaPermissionCheckActivity.this, "Por favor, confirme y acepte el acuerdo.", Toast.LENGTH_SHORT).show();
                    return;
                }
                //发布事件
                India_User_Message_ListInfoBean indiaUserMessageListInfoBean = new India_User_Message_ListInfoBean();
                indiaUserMessageListInfoBean.setCode(200);
                EventBus.getDefault().post(indiaUserMessageListInfoBean);
                finish();
            }
        });

       /* mTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent web = new Intent(PermissionAskActivity.this, MyServiceWebViewActivity.class);
                web.putExtra("webUrl", "http://adminmxwa.cmd2019.cn/appapi/login/contract");
                startActivity(web);
            }
        });*/
    }

    protected void india_Set_Immersive() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            //设置状态栏颜色透明
            window.setStatusBarColor(Color.TRANSPARENT);
            int visibility = window.getDecorView().getSystemUiVisibility();
            //布局内容全屏展示
            visibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
            //隐藏虚拟导航栏
            //visibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            //防止内容区域大小发生变化
            visibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            window.getDecorView().setSystemUiVisibility(visibility);
        } else {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
}
